package com.xiaxiaoge.tutorialmod.entity.custom;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Shearable;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.entity.monster.RangedAttackMob;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.extensions.IForgeLivingEntity;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;


/**
 * @author 夏小哥
 * @version 1.0
 * 抽象模组的叮咚🐥
 */
public class DingDongChickenEntity extends SnowGolem implements Shearable, RangedAttackMob, net.minecraftforge.common.IForgeShearable, IAnimatable, IForgeLivingEntity {

    // 动画工厂
    private final AnimationFactory factory = new AnimationFactory(this);

    public DingDongChickenEntity(EntityType<? extends SnowGolem> p_29902_, Level p_29903_) {
        super(p_29902_, p_29903_);
    }


    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
        if (event.isMoving()) {
            // 待后续补充 行走动作
            event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.dingdong_chicken.walk", true));
            return PlayState.CONTINUE;
        }
//        event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.diamonsurd.idle", true));
        return PlayState.CONTINUE;
    }

    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController(this, "controller",
                0, this::predicate));
    }

    @Override
    public AnimationFactory getFactory() {
        return factory;
    }

    // 定义实体属性
    public static AttributeSupplier setAttributes() {
        return SnowGolem.createAttributes()
                .add(Attributes.MAX_HEALTH, 10.0)
                .add(Attributes.MOVEMENT_SPEED, 0.25)
                .build();
    }

}
